<%@ page language="java"
         import="java.util.*,com.shop.mall.dao.impl.*,com.shop.mall.entity.*,com.shop.mall.utils.*"
         pageEncoding="utf-8" %>
<%@ page import="com.shop.mall.utils.Pages" %>
<%@ page import="com.shop.mall.entity.Goods" %>
<%@ page import="com.shop.mall.dao.impl.GoodsDaoImpl" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Amaze UI Admin table Examples</title>
    <meta name="description" content="这是一个 table 页面">
    <meta name="keywords" content="table">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="/static/assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="/static/assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="stylesheet" href="/static/assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="/static/assets/css/admin.css">
    <script type="text/javascript">
        function changePage(objSelect) {
            //alert(objSelect.value);
            location.href = 'goods.jsp?cpage=' + objSelect.value;
        }
    </script>
</head>
<%
    String cpage = request.getParameter("cpage");//获取当前页码
    if (cpage == null) {//如果当前页没有传入页面，默认就显示为第1页
        cpage = "1";
    }
    int pages = Integer.parseInt(cpage);//将传入的页码转换到整型
    GoodsDaoImpl edao = new GoodsDaoImpl();//实例化对象
    Pages p = edao.getlist(pages, 5, "goods", "id desc");//调用并返回集合

    List<Goods> list = (List<Goods>) p.getList();
%>
<body>
<header class="am-topbar am-topbar-inverse admin-header">
    <div class="am-topbar-brand">
        <strong>Amaze UI</strong> <small>后台管理模板</small>
    </div>

    <button class="am-topbar-btn am-topbar-toggle am-btn am-btn-sm am-btn-success am-show-sm-only" data-am-collapse="{target: '#topbar-collapse'}"><span class="am-sr-only">导航切换</span> <span class="am-icon-bars"></span></button>

    <div class="am-collapse am-topbar-collapse" id="topbar-collapse">

        <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list">
            <li><a href="javascript:;"><span class="am-icon-envelope-o"></span> 收件箱 <span class="am-badge am-badge-warning">5</span></a></li>
            <li class="am-dropdown" data-am-dropdown>
                <a class="am-dropdown-toggle" data-am-dropdown-toggle href="javascript:;">
                    <span class="am-icon-users"></span> 管理员 <span class="am-icon-caret-down"></span>
                </a>
                <ul class="am-dropdown-content">
                    <li><a href="#"><span class="am-icon-user"></span> 资料</a></li>
                    <li><a href="#"><span class="am-icon-cog"></span> 设置</a></li>
                    <li><a href="#"><span class="am-icon-power-off"></span> 退出</a></li>
                </ul>
            </li>
            <li class="am-hide-sm-only"><a href="javascript:;" id="admin-fullscreen"><span class="am-icon-arrows-alt"></span> <span class="admin-fullText">开启全屏</span></a></li>
        </ul>
    </div>
</header>
<div class="admin-content">
    <div class="admin-content-body">
        <div class="am-cf am-padding am-padding-bottom-0">
            <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">表格</strong> /
                <small>Table</small>
            </div>
        </div>

        <hr>

        <div class="am-g">
            <div class="am-u-sm-12 am-u-md-6">
                <div class="am-btn-toolbar">
                    <div class="am-btn-group am-btn-group-xs">
                        <button type="button" class="am-btn am-btn-default"><span class="am-icon-plus"></span> 新增</button>
                        <button type="button" class="am-btn am-btn-default"><span class="am-icon-save"></span> 保存</button>
                        <button type="button" class="am-btn am-btn-default"><span class="am-icon-archive"></span> 审核</button>
                        <button type="button" class="am-btn am-btn-default"><span class="am-icon-trash-o"></span> 删除</button>
                    </div>
                </div>
            </div>
            <div class="am-u-sm-12 am-u-md-3">
                <div class="am-input-group am-input-group-sm">
                    <input type="text" class="am-form-field">
                    <span class="am-input-group-btn">
            <button class="am-btn am-btn-default" type="button">搜索</button>
          </span>
                </div>
            </div>
        </div>

        <div class="am-g">
            <div class="am-u-sm-12">
                <form class="am-form">
                    <table class="am-table am-table-striped am-table-hover table-main">
                        <thead>
                        <tr>
                            <th class="table-check"><input type="checkbox"/></th>
                            <th class="table-id">ID</th>
                            <th class="table-title">名称</th>
                            <th class="table-title">简介</th>
                            <th class="table-type">标签</th>
                            <th class="table-type">库存量</th>
                            <th class="table-type">价格</th>
                            <th class="table-type">创建人</th>
                            <th class="table-type">创建日期</th>
                            <th class="table-author am-hide-sm-only">备注</th>
                        </tr>
                        </thead>

                        <%
                            for (Goods goods : list) {
                        %>
                        <tr>
                            <td><%=goods.getId()%>
                            </td>
                            <td><%=goods.getName()%>
                            </td>
                            <td><%=goods.getInfo()%>
                            </td>
                            <td><%=goods.getCategory()%>
                            </td>
                            <td><%=goods.getNum()%>
                            </td>
                            <td><%=goods.getPrice()%>
                            </td>
                            <td><%=goods.getCreator()%>
                            </td>
                            <td><%=goods.getDescription()%>
                            </td>
                            <td><%=goods.getCreate_time()%>
                            </td>
                        </tr>
                        <%
                            }
                        %>

                        <tr>
                            <td colspan="2">共 <span style="color:red"><%=p.getTotalRecord()%></span>
                                条记录 当前：<span style="color:red"><%=p.getCurrentPage()%>/<%=p.getTotalPage()%></span>
                                <select onchange="changePage(this)">
                                    <%
                                        for (int i = 1; i <= p.getTotalPage(); i++) {
                                            if (i == p.getCurrentPage()) {
                                    %>
                                    <option value=<%=i%> selected="selected"><%=i%>
                                    </option>
                                    <%
                                    } else {
                                    %>
                                    <option value=<%=i%>><%=i%>
                                    </option>
                                    <%
                                        }
                                    %>
                                    <%
                                        }
                                    %>
                                </select>
                                <a href="goods.jsp?cpage=1">首页</a>
                                <a href="goods.jsp?cpage=<%=p.getUpPageNum()%>">上一页</a>
                                <a href="goods.jsp?cpage=<%=p.getNextPageNum()%>">下一页</a>
                                <a href="goods.jsp?cpage=<%=p.getEndPageNum()%>">尾页</a>
                            </td>
                        </tr>
                        <tbody>
                    </table>
                </form>
            </div>

        </div>
    </div>

    <footer class="admin-content-footer">
        <hr>
        <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
    </footer>
</div>
</body>
</html>
